package com.hsmw.api.controller.forman;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hsmw.api.config.jwt.CurrentHsmwUserUtils;
import com.hsmw.api.config.jwt.LoginUser;
import com.hsmw.api.service.HsmwForceRemindService;
import com.htn.common.core.base.DataResponse;
import com.htn.common.core.constant.CommonConstants;
import com.htn.common.core.utils.StringUtils;
import com.hsmw.domain.HsmwForceRemind;
import com.hsmw.domain.HsmwUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.hsmw.common.base.BaseController;

/**
 * <p>
 * 空闲车辆提醒 前端控制器
 * </p>
 *
 * @author tjy
 * @since 2021-08-16
 */
@Api(tags = "提醒表")
@RestController
@RequestMapping("/hsmw/remind/")
public class HsmwForceRemindController extends BaseController<HsmwForceRemindService,HsmwForceRemind> {



    @Autowired
    private HsmwForceRemindService hsmwForceRemindService;

    @Autowired
    private CurrentHsmwUserUtils currentHsmwUserUtils;



    @ApiOperation(value = "新增修改提醒信息表",notes = "新增修改提醒信息表",produces = "application/json")
    @PostMapping("saveOrUpdateRemind")
    public DataResponse saveOrUpdateRemind(@RequestBody HsmwForceRemind hsmwForceRemind){

        if(hsmwForceRemind == null){
            return new DataResponse(CommonConstants.ResponseStatus.FAIL,"传递参数错误");
        }

        LoginUser currentHsmwUser = currentHsmwUserUtils.getCurrentUserInfo();
        if(StringUtils.isNull(currentHsmwUser)){
            return new DataResponse(CommonConstants.ResponseStatus.FAIL,"请检查登录信息");
        }

        if(StringUtils.isNotBlank(hsmwForceRemind.getId())){
            //修改
            boolean update = hsmwForceRemindService.updateById(hsmwForceRemind);
            if(update){
                return new DataResponse(CommonConstants.ResponseStatus.SUCCESS,update);
            }
            return new DataResponse(CommonConstants.ResponseStatus.FAIL,update);
        }else {
            // 新增
            hsmwForceRemind.setUserId(currentHsmwUser.getId());
            hsmwForceRemind.setUserPhone(currentHsmwUser.getUsername());
            boolean save = hsmwForceRemindService.save(hsmwForceRemind);
            if(save){
                return new DataResponse(CommonConstants.ResponseStatus.SUCCESS,save);
            }
            return new DataResponse(CommonConstants.ResponseStatus.FAIL,save);
        }

    }


    @ApiOperation(value = "取消提醒",notes = "取消提醒",produces = "application/json")
    @ApiImplicitParam(name = "id",value = "工长id",dataType = "String")
    @PostMapping("deleteRemindById")
    public DataResponse deleteRemindById(String id){

        boolean remove = hsmwForceRemindService.remove(new LambdaQueryWrapper<HsmwForceRemind>().eq(HsmwForceRemind::getUserId, id));
        if(remove){
            return new DataResponse(CommonConstants.ResponseStatus.SUCCESS);
        }
        return new DataResponse(CommonConstants.ResponseStatus.FAIL);

    }

}

